﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace octopus_project.enumeration
{ 
    public enum Direction
    {
        W,
        NW,
        N,
        NE,
        E,
        SE,
        S,
        SW
    }

    public static class DirectionExtensions {

        /// <summary>
        /// Description.
        /// </summary>
        public static Direction rotateRightTwoAxis (this Direction direction) {
            Direction returnDirection = Direction.N;
            if(direction == Direction.N) {
                returnDirection = Direction.E;
            }
            else if(direction == Direction.E) {
                returnDirection = Direction.S;
            }
            else if(direction == Direction.S) {
                returnDirection = Direction.W;
            }
            else if(direction == Direction.W) {
                returnDirection = Direction.N;
            }
            return returnDirection;
        }

        /// <summary>
        /// Description.
        /// </summary>
        public static int getRelativeAbscissa (this Direction direction, int x) {
            int returnValue = 0;

            switch(direction) {
                case Direction.W:
                    returnValue = x - 1;
                    break;
                case Direction.NW:
                    returnValue = x - 1;
                    break;
                case Direction.N:
                    returnValue = x;
                    break;
                case Direction.NE:
                    returnValue = x + 1;
                    break;
                case Direction.E:
                    returnValue = x + 1;
                    break;
                case Direction.SE:
                    returnValue = x + 1;
                    break;
                case Direction.S:
                    returnValue = x;
                    break;
                case Direction.SW:
                    returnValue = x - 1;
                    break;
            }

            return returnValue;
        }

        public static int getRelativeOrdinate (this Direction direction, int y) {
            int returnValue = 0;

            switch(direction) {
                case Direction.W:
                    returnValue = y;
                    break;
                case Direction.NW:
                    returnValue = y - 1;
                    break;
                case Direction.N:
                    returnValue = y - 1;
                    break;
                case Direction.NE:
                    returnValue = y - 1;
                    break;
                case Direction.E:
                    returnValue = y;
                    break;
                case Direction.SE:
                    returnValue = y + 1;
                    break;
                case Direction.S:
                    returnValue = y + 1;
                    break;
                case Direction.SW:
                    returnValue = y + 1;
                    break;
            } // end switch

            return returnValue;
        }

    }
}